package br.com.todirango;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		String pNome = "";
		int idCliente = 0;
		Intent it = getIntent();
		if (it != null) {
			Bundle params = it.getExtras();
			if (params != null) {
				pNome = params.getString("nomeCliente");
				idCliente = params.getInt("idCliente");
			}
		}
		TextView Txtuser = (TextView) findViewById(R.id.txtUser);
		Txtuser.setText("Bem vindo ao App ToDiRango, " + pNome);
		
		GravaPreferencias(pNome,idCliente);
	}

	public void iniciar(View view) {
		Intent it = new Intent(this, GenerosActivity.class);
		startActivity(it);
	}

	public void faleConoscoOnclick(View view) {
		 Intent it = new Intent(Intent.ACTION_CALL, Uri.parse("tel:(79)99234545"));
		 startActivity(it);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	public void GravaPreferencias( String nomeCliente, int idCliente) {
		 
		SharedPreferences  sharedPreferences = getSharedPreferences("preferencia", Context.MODE_PRIVATE);
		 
		Editor prefsPrivateEditor = sharedPreferences.edit();
		 
		prefsPrivateEditor.putString("nomeCliente", nomeCliente);
		prefsPrivateEditor.putInt("idCliente", idCliente);
		 
		prefsPrivateEditor.commit();
		 
		}

}
